package com.ltg.urban.domain.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltg.framework.util.http.Result;
import com.ltg.urban.domain.project.data.response.StatisticsResp;
import com.ltg.urban.domain.project.data.response.UrbanProjectResp;
import com.ltg.urban.domain.project.entity.UrbanProject;
import com.ltg.urban.domain.project.entity.UrbanProjectCapital;
import com.ltg.urban.domain.project.entity.UrbanProjectCapitalDetail;
import com.ltg.urban.domain.project.entity.UrbanProjectUser;
import com.ltg.urban.domain.project.mapper.UrbanProjectCapitalDetailMapper;
import com.ltg.urban.domain.project.mapper.UrbanProjectCapitalMapper;
import com.ltg.urban.domain.project.mapper.UrbanProjectMapper;
import com.ltg.urban.domain.project.service.UrbanProjectService;
import com.ltg.urban.domain.project.service.UrbanStatisticsService;
import com.ltg.urban.domain.sys.entity.SysUser;
import com.ltg.urban.domain.sys.mapper.SysUserMapper;
import com.ltg.urban.domain.sys.service.SysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p> ClassName: UrbanStatisticsServiceImpl </p>
 * <p> Package: com.ltg.urban.domain.project.service.impl </p>
 * <p> Description: </p>
 * <p></p>
 *
 * @Author: LTG
 * @Create: 2023/3/6 - 21:53
 * @Version: v1.0
 */
@Service
@RequiredArgsConstructor
public class UrbanStatisticsServiceImpl implements UrbanStatisticsService {
    private final SysUserMapper sysUserMapper;
    private final UrbanProjectMapper urbanProjectMapper;
    private final UrbanProjectCapitalMapper urbanProjectCapitalMapper;
    private final UrbanProjectCapitalDetailMapper urbanProjectCapitalDetailMapper;


    @Override
    public Result<List<Integer>> statistics() {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(sysUserMapper.selectCount(null).intValue());
        list.add(urbanProjectMapper.selectCount(null).intValue());
        list.add(urbanProjectCapitalMapper.selectAllTotal().intValue());
        list.add(urbanProjectCapitalDetailMapper.selectCount(null).intValue());
        return Result.success(list);
    }

    @Override
    public Result<List<UrbanProjectResp>> indexList() {

        List<UrbanProjectResp> list = new ArrayList<>();
        List<UrbanProject> urbanProjects = urbanProjectMapper.selectList(null);

        for (UrbanProject urbanProject : urbanProjects) {
            LambdaQueryWrapper<UrbanProjectCapital> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(UrbanProjectCapital::getProjectId,urbanProject.getId());
            UrbanProjectCapital urbanProjectCapital = urbanProjectCapitalMapper.selectOne(wrapper);
            UrbanProjectResp urbanProjectResp = new UrbanProjectResp();
            urbanProjectResp.setId(urbanProject.getId());
            urbanProjectResp.setProjectName(urbanProject.getProjectName());
            urbanProjectResp.setCreateTime(urbanProject.getCreateTime());
            urbanProjectResp.setActualCost(urbanProjectCapital.getActualCost());
            list.add(urbanProjectResp);
        }
        return Result.success(list);

    }
}
